package com.kyzh.core.adapters

import android.app.Activity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.TextView
import com.gushenge.core.beans.PhoneCodeBean
import com.kyzh.core.R
import com.kyzh.core.utils.dip

class PhoneCodeAdapter(context: Activity, val layout: Int, val beans: ArrayList<PhoneCodeBean>):
    ArrayAdapter<PhoneCodeBean>(context, layout, beans){

    inner class ViewHolder(val textView: TextView,val textView2: TextView)
    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        val viewHolder : ViewHolder
        val view :View
        if (convertView ==null){
            view = LayoutInflater.from(context).inflate(layout, null)
            val textView = view.findViewById<TextView>(R.id.tv_left)
            val textView2 = view.findViewById<TextView>(R.id.tv_right)
            viewHolder = ViewHolder(textView,textView2)
            view.tag = viewHolder
        }else{
            view = convertView
            viewHolder = view.tag as ViewHolder
        }
        viewHolder.textView.text = beans[position].code
        viewHolder.textView.textAlignment = View.TEXT_ALIGNMENT_CENTER
//        viewHolder.textView2.text = beans[position].code
//        viewHolder.textView2.textAlignment = View.TEXT_ALIGNMENT_CENTER
        return view
    }

    override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup): View {
        val viewHolder : ViewHolder
        val view :View
        if (convertView ==null){
            view = LayoutInflater.from(context).inflate(layout, null)
            val textView = view.findViewById<TextView>(R.id.tv_left)
            val textView2 = view.findViewById<TextView>(R.id.tv_right)
            viewHolder = ViewHolder(textView,textView2)
            view.tag = viewHolder
        }else{
            view = convertView
            viewHolder = view.tag as ViewHolder
        }
        getItem(position)?.let {
            viewHolder.textView.height = context.dip(40)
            viewHolder.textView2.height = context.dip(40)
            viewHolder.textView.text = it.name
            viewHolder.textView2.text = it.code
        }
        return view
    }
}
